/*******************************************************************************
 * Copyright (c) 2006 CEA List.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     CEA List - initial API and implementation
 *******************************************************************************/
package com.cea.papyrus.diagram.deployment.helper;

import org.eclipse.uml2.uml.CommunicationPath;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.Node;
import org.eclipse.uml2.uml.Package;
import org.eclipse.uml2.uml.UMLFactory;

import com.cea.papyrus.core.utils.Debug;
import com.cea.papyrus.diagraminterchange2.di2.GraphElement;

/**
 * Defines management of communication paths.
 * 
 * @author Gilles Cannenterre
 * @since 15 janv. 07
 */
public class EdgeCommunicationPathHelper extends EdgeAssociationHelper {

	/**
	 * The channel.
	 */
	private int channel = 203;

	/**
	 * 
	 * 
	 * @return 
	 */
	public String getBaseString() {
		return "CommunicationPath_"; //$NON-NLS-1$
	}

	/**
	 * 
	 * 
	 * @param umlParent 
	 * @param name 
	 * 
	 * @return 
	 */
	public  Element createUMLElement(String name, Element umlParent){
		Debug.debug(this,"createUMLElement(String,Element)", channel); //$NON-NLS-1$
		CommunicationPath aCommunicationPath = UMLFactory.eINSTANCE.createCommunicationPath();
		aCommunicationPath.setName(name);
		((Package)umlParent.getNearestPackage()).getPackagedElements().add(aCommunicationPath);
		return aCommunicationPath;		
	}

	/* (non-Javadoc)
	 * @see com.cea.papyrus.common.factories.GraphEdgeFactory#canConnect(org.eclipse.uml2.uml.Element, org.eclipse.uml2.uml.Element)
	 */
	/**
	 * 
	 * 
	 * @param target 
	 * @param source 
	 * 
	 * @return 
	 */
	@Override
	public boolean canConnect(Element source,Element target){
		if(source instanceof Node && target==null){return true;}
		if ((source instanceof Node) && (target instanceof Node)) {
			return true;
		}
		return false;
	}

	/*
	 * (non-Javadoc)
	 * @see com.cea.papyrus.common.factories.GraphEdgeFactory#canExecute(com.cea.papyrus.diagraminterchange2.di2.GraphNode)
	 */
	/**
	 * 
	 * 
	 * @param source 
	 * 
	 * @return 
	 */
	@Override
	public boolean canCreateGraphElement(GraphElement source){
		return super.canCreateGraphElement(source);
	}
}